<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'user_add.jsp' starting page</title>
    
    <link rel="stylesheet" type="text/css" href="js/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="js/themes/icon.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/locale/easyui-lang-zh_CN.js"></script>
    
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">
		$(function(){
			 $.extend($.fn.validatebox.defaults.rules, {   	
			      minLength: {   	
			          validator: function(value, param){   	
			              return value.length >= param[0];   	
			          },   	
			          message: ''  	
			      }
			  });
			 
			  $('#grid').datagrid({   
				  	  idField:'id',
				      url:'json/client_search.action', 
				      striped:true,
				      loadMsg:'正在加载中，请等待....',
				      pagination:true,
				      fitColumns:true,
				      rownumbers:true,
				      pageSize:7,
				      pageList:[7,14,21,28,35],
				      
				      frozenColumns:[
										[{
											field:'cb',
											checkbox:true									
										 }]				               
						               ],
				      columns:[[   
				          {field:'name',title:'分销商',width:100},   
				          {field:'bankAccount',title:'银行账号',width:100},   
				          {field:'tel',title:'联系电话',width:100},   
				          {field:'address',title:'联系地址',width:100},  
				          {field:'isClient',title:'身份',width:100,
				        	  formatter:function(value,rowDate,index){
					        	  if(value == 'false'){
					        		  return '分销商';
					        	  } else {
					        		  return '区域';
					        	  }
				          }},
				          {field:'zipCode',title:'邮政编码',width:100,}
				      ]] ,
				      toolbar:[{
							text:'编辑分销商',
							iconCls:'icon-edit',
							handler:function(){
								var arr = $('#grid').datagrid('getSelections');
								if(arr.length == 1){
									$('#myform').get(0).reset();
									$('#dialog').dialog('open');
									$('#myform').form('load',{
										"client.id":arr[0].id,
										"client.zipCode":arr[0].zipCode,
										"client.name":arr[0].name,
										"client.tel":arr[0].tel,
										"client.bankAccount":arr[0].bankAccount,
										"client.address":arr[0].address,
										"client.isClient":arr[0].isClient
									});
								} else {
									$.messager.alert('提示','请选择一个分销商编辑','warning'); 
								}
							}
						}]
				  });
			  $('#save').click(function(){
				    $('#myform').form('submit', {   
					        url:'json/client_modify.action',   
					        onSubmit: function(){  
					        	if(!$('#myform').form('validate')){
					        		return false;
					        	}
					        },   
					        success:function(){  
					        	$('#dialog').dialog('close');
					        	$('#grid').datagrid('reload');
					        	$.messager.show({
					        		title:'提示',
					        		height:170,
					        		msg:'修改成功'
					        	});
					       }   
					   });				    			
			  });
			  
			  $('#cancel').click(function(){
					$('#dialog').dialog('close');
				});
			    				  
			  $('#search').searchbox({   
				     width:200,   
				     searcher:function(value){   
				         $('#grid').datagrid('load',{key:value});  
				     },     
				     prompt:'请输入关键字'  
				 });
		});
		
		function editable(){
			$('#bankAccount').attr('disabled',false);
			$('#tel').attr('disabled',false);
			$('#address').attr('disabled',false);
			$('#zipCode').attr('disabled',false);
		
		}
		
		function read(){
			$('#bankAccount').attr('disabled',true);
			$('#tel').attr('disabled',true);
			$('#address').attr('disabled',true);
			$('#zipCode').attr('disabled',true);
		}
	</script>

  </head>
  
  <body>
  		关键字：<input id="search" name="key"></input>
  		<br><br><br>
		<table id="grid"></table>  	 		 	 	 	
		<div id="dialog" class="easyui-dialog" title="设置分销商" draggable=false closed=true resizable=false modal=true style="width:300px;">  	     	 
			<form id="myform" action="" method="post">
				 <input type="hidden" name="client.id" value=""/>
			  		<table>
			  			<tr>
			  				<td>类型</td>
			  				<td>
			  					 <input type="radio" name="client.isClient" value="true" checked="checked" onclick="editable()">分销商
			  					 <input type="radio" name="client.isClient" value="false" onclick="read()">区域
			  				</td>
			  			</tr>
			  			<tr>
			  				<td>分销商名</td>
			  				<td>
			  					<input type="text" name="client.name" class="easyui-validatebox" required=true 
			  						missingMessage="分销商名必填" validType="minLength[2]" invalidMessage="分销商名至少2个字符"
			  						style="width:200px;">
			  				</td>
			  			</tr>			  			
			  			<tr>
			  				<td>银行账号</td>
			  				<td>
			  					<input type="text" name="client.bankAccount" style="width:200px;">
			  				</td>
			  			</tr>
			  			<tr>
			  				<td>电话</td>
			  				<td>
			  					<input type="text" name="client.tel"  style="width:200px;">
			  				</td>
			  			</tr>
			  			<tr>
			  				<td>地址</td>
			  				<td>
			  					<input type="text" name="client.address" style="width:200px;">
			  				</td>
			  			</tr>
			  			<tr>
			  				<td>邮政编码</td>
			  				<td>
			  					<input type="text" name="client.zipCode" style="width:200px;">
			  				</td>
			  			</tr>
			  			<tr>			  			
			  				<td align="center" colspan="2">
			  					<a id="save" class="easyui-linkbutton">确定</a>
			  					<a id="canel" class="easyui-linkbutton">取消</a>
			  				</td>
			  			</tr>
			  		</table>	
			  	</form>
		  </div> 
  	
  </body>
</html>
